<?php

################################################################################################################
Function show_users($start, $limit)
{
  $table_users_auth = $_SESSION['prefix']."users_auth";
  $table_users_infos = $_SESSION['prefix']."users_infos";

	$connection = dbconnect();
	$req = dbquery("SELECT uid,login,mail FROM $table_users_auth WHERE 1 ORDER BY uid ASC LIMIT $start,$limit", $connection);
	if (@mysql_num_rows($req) == 0)
	{
		mysql_close($connection);
		return (-1);
    }
   
	while ($line = @mysql_fetch_array($req))
    {
		$req_2 = dbquery("SELECT last_login,valid FROM $table_users_infos WHERE uid=\"$line[uid]\"", $connection);
		$last_login = mysql_result($req_2, 0, "last_login");
		$valid = mysql_result($req_2, 0, "valid");
		
		if ($valid == "ko")
			$class = "red";
		else
			$class = "blue";
			
			Print("
				<thead>
				<tr class=\"$class\">
					<td align=center><font color=green>$line[uid]</font></td>
					<td align=left><font color=darkblue><b>$line[login]</b>");
					if (is_root($line['login'], $connection))
						Print("<small> (root)</small>");
					Print("</font></td>
					<td align=left><font color=#4B4B4B>$line[mail]</font></td>
					<td align=left><font color=#4B4B4B>$last_login</font></td>
					<td align=center>
			");
			if (!is_administrator($line['uid'], $connection))
			{
				Print("
					<a href=\"ipage.php?height=270&act=user&sub=infos&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Informations utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user.png\" width=16 height=16 title=\"Informations sur l'utilisateur $line[login]\"></a> ' 
					<a href=\"ipage.php?height=430&act=user&sub=edit&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user_edit.png\" width=16 height=16 title=\"Modifier l'utilisateur $line[login]\"></a> ' 
					<a href=\"ipage.php?height=200&act=user&sub=delete&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user_delete.png\" width=16 height=16 title=\"Supprimer l'utilisateur $line[login]\"></a>
				");
			}
			else
			{
				if (!is_root($_SESSION['login'], $connection))
					Print(" - ");
				else
				{
					Print("
						<a href=\"ipage.php?height=270&act=user&sub=infos&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Informations utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user.png\" width=16 height=16 title=\"Informations sur l'utilisateur $line[login]\"></a> ' 
						<a href=\"ipage.php?height=430&act=user&sub=edit&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=royalblue><b>Edition utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user_edit.png\" width=16 height=16 title=\"Modifier l'utilisateur $line[login]\"></a> ' 
						<a href=\"ipage.php?height=200&act=user&sub=delete&uid=$line[uid]\" class=\"thickbox\" title=\"<font color=red><b>Suppression utilisateur</b></font>\"><img src=\"$_SESSION[current_path]/images/user_delete.png\" width=16 height=16 title=\"Supprimer l'utilisateur $line[login]\"></a>
					");
				}
					
			}
			
			Print("						
					</td>
				</tr>
				</thead>
			");
	}
	mysql_close($connection);
	return;
}

################################################################################################################
Function show_user_infos($uid)
{
	imports ("odt_frm_php.users");
	
	$user_infos = get_user_infos($uid);
	$user_infos_2 = get_user_infos_2($uid);
	$template = get_template_infos($user_infos['tid']);
	
	Print("
		<div id=\"box\">
			<h3>$user_infos[login]</h3>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>UID:</font></b></td>
					<td><font color=#4B4B4B>$uid</font></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>E-mail:</font></b></td>
					<td><font color=#4B4B4B>$user_infos[mail]</font></td>
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Derni&egrave;re connexion:</font></b></td>
					<td><font color=#4B4B4B>$user_infos_2[last_login]</font></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Derni&egrave;re adresse IP:</font></b></td>
					<td><font color=#4B4B4B>$user_infos_2[last_ip]</font></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Status du compte:</font></b></td>");
				
				if ($user_infos_2['valid'] == "ok")
					Print("<td><font color=green><b>Valide</b></font> <img src=\"$_SESSION[path_images]/valid.png\"></td>");
				else
					Print("<td><font color=red><b>D&eacute;sactiv&eacute;</b></font> <img src=\"$_SESSION[path_images]/stop.png\"></td>");
			Print("
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Groupes: </font></b></td>
					<td>");
						show_user_select_groups(get_user_groups($uid));
					Print("</td>
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Template:</font></b></td>
					<td><font color=#4B4B4B>$template[name]</font></td>
				</tr>
			</table>
		</div>
	");
	return;
}

################################################################################################################
Function show_user_edit($uid)
{
	imports ("odt_frm_php.users");
	
	$user_infos = get_user_infos($uid);
	$user_infos_2 = get_user_infos_2($uid);
	$template = get_template_infos($user_infos['tid']);
	
	Print("
		<div id=\"box\">
			<h3>$user_infos[login]</h3>
			<form action=\"users.php\" method=POST>
			<input type=hidden name=\"act\" value=\"edit_user\">
			<input type=hidden name=\"uid\" value=\"$uid\">
			<input type=hidden name=\"status2\" value=\"$user_infos_2[valid]\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>UID:</font></b></td>
					<td><font color=#4B4B4B>$uid</font></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>E-mail:</font></b></td>
					<td><input type=text name=\"mail\" value=\"$user_infos[mail]\" size=30></td>
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Derni&egrave;re connexion:</font></b></td>
					<td><font color=#4B4B4B>$user_infos_2[last_login]</font></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Derni&egrave;re adresse IP:</font></b></td>
					<td><font color=#4B4B4B>$user_infos_2[last_ip]</font></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Status du compte:</font></b></td>");
				
				if ($user_infos_2['valid'] == "ok")
					Print("<td><font color=green><b>Valide</b></font> <img src=\"$_SESSION[path_images]/valid.png\"> - <input type=radio name=\"status\" value=\"ko\"> D&eacute;sactiver</td>");
				else
					Print("<td><font color=red><b>D&eacute;sactiv&eacute;</b></font> <img src=\"$_SESSION[path_images]/stop.png\"> - <input type=radio name=\"status\" value=\"ok\"> Activer</td>");
			Print("
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Mot de passe:</font></b></td>
					<td><input type=text name=\"pass1\"></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Confirmation:</font></b></td>
					<td><input type=text name=\"pass2\"></td>
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Ses groupes:</font></b></td>
					<td>");
						show_user_select_groups(get_user_groups($uid));
					Print("</td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Ajouter au groupe:</font></b></td>
					<td>");
						show_select_groups(get_gids(), TRUE);
					Print("</td>
				</tr>
			</table>
			<hr color=#4B4B4B>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>Template:</font></b></td>
					<td>");
						show_templates_list($user_infos['tid']);
					Print("</td>
				</tr>
			</table>
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td align=right><input type=submit value=\"Modifier\"></td>
				</tr>
			</table>
		</form>
		</div>
	");
	return;
}

################################################################################################################
Function show_user_delete($uid)
{
	imports ("odt_frm_php.users");
	
	$user_infos = get_user_infos($uid);
	$user_infos_2 = get_user_infos_2($uid);
	$template = get_template_infos($user_infos['tid']);
	
	Print("
		<div id=\"box\">
			<h3>
			<table border=0>
				<tr>
					<td width=40><img src=\"$_SESSION[path_images]/large/delete_1.png\" width=40 height=40></td>
					<td><font size=3>Supprimer l'utilisateur $user_infos[login]</font></td>
				</tr>
			</table>
			</h3>
			<center>
				<br>
				<font color=\"red\"><b>Voulez vous continuer ?</b></font>
				<br>
				<table border=0 width=100%>
					<tr>
						<td width=50% align=right>
							<form action=\"users.php\" method=POST>
								<table>
									<tr>
										<td align=right><input type=submit value=\"Annuler\"></td>
									</tr>
								</table>
							</form>
						</td>
						<td>
							<form action=\"users.php\" method=POST>
							<input type=hidden name=\"act\" value=\"delete_user\">
							<input type=hidden name=\"uid\" value=\"$uid\">
							<table>
								<tr>
									<td><input type=submit value=\"Supprimer\"></td>
								</tr>
							</table>
							</form>
						</td>
					</tr>
				</table>
			</center>
		</div>
	");
	return;
}

################################################################################################################
Function show_user_new()
{
	Print("
		<div id=\"box\">
			<form action=\"users.php\" method=POST>
			<h3>Utilisateur: <input type=text name=\"user\"></h3>
			<input type=hidden name=\"act\" value=\"new_user\">
			<table cellpadding=0 cellspacing=0 border=0 width=100%>
				<tr>
					<td width=30%><b><font color=royalblue>E-mail:</font></b></td>
					<td><input type=text name=\"mail\" size=30></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Mot de passe:</font></b></td>
					<td><input type=text name=\"pass1\"></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Confirmation:</font></b></td>
					<td><input type=text name=\"pass2\"></td>
				</tr>
				<tr>
					<td><b><font color=royalblue>Template:</font></b></td>
					<td>");
						show_templates_list();
					Print("</td>
				</tr>
				<tr>
					<td></td>
					<td></td>
					<td align=right><input type=submit value=\"Ajouter\"></td>
				</tr>
			</table>
		</form>
		</div>
	");
	return;
}

?>